package westh.ilib.service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.regex.*;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.lucene.demo.SearchFiles;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOMessage;
import westh.ilib.util.ConvertRscToCDOIRsc;
import westh.log.YyError;
import westh.config.Config;

/**
 * 
 * author:  @author yanfei
 * date  :  Aug 10, 2010
 * modified:zhangjian 
 * date    :2010-09-15
 * content :add method get clouds Ip address
 */

public class ResourceService {

	//get clouds Ip address
	String localhostUrl = Config.get("localhostUrl");
	String remoteUrl = Config.get("remoteUrl");

	/**
	 * function: Get the resource list by input json from multi domain
	 * Input: the input json string
	 * output: the resource list json string
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String getResouceListByJson(String inputStrJson, Log log)throws Exception
	{
		String retCode="4501";
		String retMsg="Failure!";
		String result="";
		JSONObject outStringJson=new JSONObject();
		outStringJson.put("retCode", retCode);
		outStringJson.put("retMsg",retMsg);
		String outString = "";
		JSONObject json=JSONObject.fromObject(inputStrJson);
		String query=json.getString("query");
		//Pattern  p=Pattern.compile("(\\s)*");
		//Matcher m=p.matcher(query);
		if(query.matches("(\\s)*")){
			outStringJson.put("result","[]");
			outString=outStringJson.toString();
			return outString;
		}
		JSONArray rscFieldList=json.getJSONArray("rscFieldList");
		JSONArray rscTypeList=json.getJSONArray("rscTypeList");
		
		JSONObject inputJson=new JSONObject();
		inputJson.put("query", query);
		inputJson.put("rscTypeList", rscTypeList);
		
		JSONArray totalRscListJson=new JSONArray();
		List jsonArrayList=new ArrayList();
		
		//Get resource from CDO
		String cdoRscList="";
//		String cdoRscList=this.getRscListFromCdo(inputStrJson,log);
		if(!cdoRscList.equals("")){
			JSONArray cdoRscListJson=JSONArray.fromObject(cdoRscList);
			totalRscListJson.addAll(cdoRscListJson);
			jsonArrayList.add(cdoRscListJson);
		}
		List list=new ArrayList();
		for(int i=0;i<rscFieldList.size();i++)
			list.add(rscFieldList.getString(i));
		//OAI field
		if(list.contains("2")){
			String oaiRscList=this.getRscListFromOAI(inputStrJson,log);
			if(!oaiRscList.equals("")){
				JSONArray oaiRscListJson=JSONArray.fromObject(oaiRscList);
				totalRscListJson.addAll(oaiRscListJson);
				jsonArrayList.add(oaiRscListJson);
			}
		}
		//TLib field
		if(list.contains("4")){
			String tLibRscList=this.getRscListFromTLib(inputStrJson,log);
			if(!tLibRscList.equals("")){
				JSONArray tLibRscListJson=JSONArray.fromObject(tLibRscList);
				totalRscListJson.addAll(tLibRscListJson);
				jsonArrayList.add(tLibRscListJson);
			}
		}
		//TagSys field
		if(list.contains("5")){
				String tSysRscList=this.getRscListFromTSys(inputStrJson,log);
				if(!tSysRscList.equals("")){
					JSONArray tSysRscListJson=JSONArray.fromObject(tSysRscList);
					totalRscListJson.addAll(tSysRscListJson);
					jsonArrayList.add(tSysRscListJson);
				}
		}
		//Merge results from different fields.
		log.debug("jsonArrayList="+jsonArrayList.size());
		ResourceRanking rankModel=new ResourceRanking(jsonArrayList);
		log.debug("Finished merging results.");
		result=rankModel.mergeResults();
		
		
		outStringJson.put("retCode", "4501");
		outStringJson.put("retMsg", "Success!");
		outStringJson.put("result", result);
		outString=outStringJson.toString();
		log.debug("outString");
		return outString;
	}
	/**
	 * get resources from multi fields via multi-thread approach
	 * @param inputStrJson
	 * @param log
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String getResouceListByJsonMul(String inputStrJson, Log log)throws Exception{
		String outString="[]";
		JSONObject json=JSONObject.fromObject(inputStrJson);
		JSONArray rscFieldList=json.getJSONArray("rscFieldList");
		List jsonArrayList=new ArrayList();
		CountDownLatch threadSignal = new CountDownLatch(rscFieldList.size());
		for(int i=0;i<rscFieldList.size();i++){
			Thread t=new MultiThread(threadSignal,this,inputStrJson,rscFieldList.getString(i),jsonArrayList,log);
			t.start();
		}
		threadSignal.await();
		System.out.println(Thread.currentThread().getName() + "结束.");
		//Merge results from different fields.
		log.debug("jsonArrayList="+jsonArrayList.size());
		ResourceRanking rankModel=new ResourceRanking(jsonArrayList);
		log.debug("Finished merging results.");
		String result=rankModel.mergeResults();
		
		JSONObject outStringJson=new JSONObject();
		outStringJson.put("retCode", "4501");
		outStringJson.put("retMsg", "Success!");
		outStringJson.put("result", result);
		outString=outStringJson.toString();
		//log.debug("outString");
		return outString;
	}
	/**
	 * Created by Jian Tang
	 * Get resource from OAI field
	 * @param inputStr
	 * @return
	 * @throws Exception
	 */
	public String getRscListFromOAI(String input,Log log)throws Exception
	{
		log.debug("oaiInputString= "+input);
		String outString = SearchFiles.getRscListJson(input);
		JSONObject json=JSONObject.fromObject(outString);
		String result=json.getString("result");
	    //log.debug("oaiOutString= "+result);
	    //log.debug("register resources.");
	    String registerResults=this.regRscListToCdoi(result,log);
	    //log.debug("register results="+registerResults);
	    log.debug("Finished getting rscs from oai.");
		return registerResults;		
		//return result;
	}
	/**
	 * Created by Jian Tang
	 * Get resource from TagSystem Field
	 * @param input
	 * @return
	 */
	public String getRscListFromTSys(String input,Log log){
		log.debug("tSysInput="+input);
	    String outString="";
	try {
		MuleClient clientD = new MuleClient();
		// 调用WebService
		UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":9181/QCenter/TagQcenter?method=getRscFromTSys",input, null);
		outString= (String) umo.getPayload();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	JSONObject json=JSONObject.fromObject(outString);
	String result=json.getString("result");
	//log.debug("tSysOutString= "+outString);
	 String registerResults=this.regRscListToCdoi(result,log);
	 log.debug("Finished getting rscs from TSys.");
		return registerResults;
	}
	/**
	 * Created by Jian Tang
	 * Get resource from TLib Field;
	 * @param input
	 * @return
	 */
	public String getRscListFromTLib(String input,Log log)
	{
		log.debug("tTLIbInput="+input);
	    String outString="";
	try {
		MuleClient clientD = new MuleClient();
		// 调用WebService
		UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":3981/tLib/tLibSys?method=getRscFromTLib",input, null);
		outString= (String) umo.getPayload();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
    	//log.debug("TLibOutput="+outString);
		JSONObject json=JSONObject.fromObject(outString);
		String result=json.getString("result");
		String registerResults=this.regRscListToCdoi(result,log);
		 log.debug("Finished getting rscs from TLib.");
		return registerResults;
		//return "";
	}
	
	/**
	 * created by Jian Tang
	 * Get resource from Cdo Field;
	 * @param input
	 * @return
	 */
	public String getRscListFromCdo(String input,Log log)
	{
		log.debug("cdoInput="+input);
	    String outString="";
	try {
		MuleClient clientD = new MuleClient();
		// 调用WebService
		UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":3981/tLib/tLibSys?method=getRscFromCdo",input, null);
		outString= (String) umo.getPayload();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
    //	log.debug("cdoOutput="+outString);
		JSONObject json=JSONObject.fromObject(outString);
		String result=json.getString("result");
		String registerResults=this.regRscListToCdoi(result,log);
		 log.debug("Finished getting rscs from cdo.");
		return registerResults;
	}
	/**
	 * created by Jian Tang
	 * 13th, Aug, 2010.
	 * register resources into cdoi, return resouces with ids;
	 * @param input
	 * @return
	 */
	public String regRscListToCdoi(String input,Log log)
	{
		log.debug("register resources");
		
		JSONArray jsonArray=JSONArray.fromObject(input);
		if(jsonArray.size()==0) return "";
		String inputStr=ConvertRscToCDOIRsc.convertRscListToCdoi(jsonArray,log);
		//log.debug("register resources="+inputStr);
		String cdoiIds="";
		
		try{
			  MuleClient clientW = new MuleClient();
//			  UMOMessage umo = clientW.send("axis:http://192.168.28.112:4281/Cdoi/cdoiCdoi?method=addJson",cdoiJson,null);
			  UMOMessage umo = clientW.send("axis:http://"+remoteUrl+":4281/Cdoi/cdoiCdoi?method=addJsonList",inputStr,null);
			  cdoiIds = (String)umo.getPayload();
		  } catch (Exception e) {
			throw new RuntimeException(e);
		  }
		//  log.debug("register results="+cdoiIds);
		  
		JSONArray idArray=JSONArray.fromObject(cdoiIds);
		if(jsonArray.size()!=idArray.size()){
			YyError.show("4601");//The number of returned ids is not consistent with the number of sent resources!
			return null;
		}
		JSONArray rscIdArray=new JSONArray();
		JSONArray rscSaveArray=new JSONArray();
		JSONArray rscSaveIdArray=new JSONArray();
		
		JSONArray finalArray=new JSONArray();
		for(int i=0;i<jsonArray.size();i++){
			JSONObject rsc=regRscAuthors( jsonArray.getJSONObject(i),log);
			finalArray.add(rsc);
		}
		for(int i=0;i<idArray.size();i++){
			JSONObject json=idArray.getJSONObject(i);
			String rscId=json.getString("rscId");
			rscIdArray.add(rscId);
			String repeat=json.getString("repeat");
			if(repeat.equals("0")){
				
				//JSONObject rsc=regRscAuthors( jsonArray.getJSONObject(i),log);
				rscSaveArray.add(finalArray.getJSONObject(i));
				//rscSaveArray.add((rsc));
				rscSaveIdArray.add(rscId);
			}
		}
		//
		String rscSaveJson=ConvertRscToCDOIRsc.addRscIds(rscSaveArray,rscSaveIdArray);
		//add new resources to Cdo
		if(rscSaveArray.size()!=0)
			this.saveRscListToCdo(rscSaveJson,log);
		//add resource ids;
		String json=ConvertRscToCDOIRsc.addRscIds(finalArray, rscIdArray);
		log.debug("Finish registering resources.");
		return json;
	}
	/**
	 * Register authors into cdoi;
	 * @param input
	 * @param log
	 * @return author id list.
	 */
	public String regAuthorListToCdoi(String input, Log log){
		//log.debug("register authors input:"+input);
		log.debug("register authors");
		String cdoiIds="";
		try{
			  MuleClient clientW = new MuleClient();
//			  UMOMessage umo = clientW.send("axis:http://192.168.28.112:4281/Cdoi/cdoiCdoi?method=addJson",cdoiJson,null);
			  UMOMessage umo = clientW.send("axis:http://"+remoteUrl+":4281/Cdoi/cdoiCdoi?method=addAuthorList",input,null);
			  cdoiIds = (String)umo.getPayload();
		  } catch (Exception e) {
			throw new RuntimeException(e);
		  }
		//  log.debug("register author results="+cdoiIds);
		  JSONArray authorArray=JSONArray.fromObject(input);
		  JSONArray idArray=JSONArray.fromObject(cdoiIds);
		  if(authorArray.size()!=idArray.size()){
				YyError.show("4602");//The number of returned ids is not consistent with the number of sent resources!
				return null;
		  }
		//String outString=ConvertRscToCDOIRsc.addAuthorIds(authorArray, idArray);
		return cdoiIds;
	}
	/**
	 * add ids to authors into resources.
	 * @return
	 */
	public JSONObject regRscAuthors(JSONObject rsc,Log log){
		log.debug("register resource authors: "+rsc.toString());
		if(rsc==null) return null;
		String firstAuthorJson=rsc.getString("rscFirstAuthor");
		if(firstAuthorJson.equals("")) return rsc;
		
		JSONObject inputJson=null;
		String inputStr=null;
		String outPutStr=null;
		JSONArray inputJsonArray=null;
	    JSONArray outputJsonArray=null;
		//firstAuthor
	    inputJsonArray=new JSONArray();
	    outputJsonArray=new JSONArray();
		JSONObject firstAuthor=JSONObject.fromObject(firstAuthorJson);
		String firstAuthorName=firstAuthor.getString("name");
		if(firstAuthorName.equals("")||firstAuthorName==null) return rsc;
		String institution=firstAuthor.getString("institution");
		
		inputJson=new JSONObject();
		inputJson.put("DC_TITLE", firstAuthorName);
		inputJson.put("DC_SOURCE", institution);
		inputJson.put("CDOI_AGENCY_ID", "012f717f8dde4129a95837bf153de5a0");   //注册机构编码
		inputJson.put("DC_LANGUAGE", "c7d2ec860cee4b03ba845da0233ed977");      //语种标识符
		inputJson.put("CDOI_CUSTOMER_ID", "f41825a60cf44e83b83cbd9114220f29"); //用户标识符
		inputJson.put("DC_TYPE", "27278cfe6e1c429aa2197b3ff34a11ab"); 
		inputJsonArray.add(inputJson);
		inputStr=inputJsonArray.toString();				
		outPutStr=this.regAuthorListToCdoi(inputStr, log);
		//log.debug("register outputstr="+outPutStr);
		outputJsonArray=JSONArray.fromObject(outPutStr);
		if(outputJsonArray.size()!=1)
			YyError.show("4602");
		
		JSONObject jsonObject=outputJsonArray.getJSONObject(0);
		String id=jsonObject.getString("rscId");
		firstAuthor.put("uid", id);
		rsc.put("rscFirstAuthor", firstAuthor.toString());
		
		
		//otherAuthors
		inputJsonArray=new JSONArray();
	    outputJsonArray=new JSONArray();
	    JSONArray inputArray=null;
	    JSONArray outputArray=null;
	    JSONArray finalAuthorArray=new JSONArray();
	    String otherAuthorsJson=rsc.getString("rscOtherAuthors");
	    if(!otherAuthorsJson.equals("")){
	    	inputArray=JSONArray.fromObject(otherAuthorsJson);
	    	for(int i=0;i<inputArray.size();i++){
	    		JSONObject author=JSONObject.fromObject(inputArray.get(i));
	    		String authorName=author.getString("name");
	    		if(authorName.equals("")||authorName==null) continue;
	    		String authorInst=author.getString("institution");
	    		JSONObject json=new JSONObject();
	    		json.put("DC_TITLE", authorName);
	    		json.put("DC_SOURCE", authorInst);
	  		    json.put("CDOI_AGENCY_ID", "012f717f8dde4129a95837bf153de5a0");   //注册机构编码
			    json.put("DC_LANGUAGE", "c7d2ec860cee4b03ba845da0233ed977");      //语种标识符
			    json.put("CDOI_CUSTOMER_ID", "f41825a60cf44e83b83cbd9114220f29"); //用户标识符
			    json.put("DC_TYPE", "27278cfe6e1c429aa2197b3ff34a11ab"); 
	    		inputJsonArray.add(json);
	    	}
	    	if(inputJsonArray.size()!=0){
	    			inputStr=inputJsonArray.toString();
	    			outPutStr=this.regAuthorListToCdoi(inputStr, log);
	    			outputArray=JSONArray.fromObject(outPutStr);
	    			if(outputArray.size()!=inputArray.size())
	    				YyError.show("4602");
	    			for(int i=0;i<inputArray.size();i++){
	    				JSONObject author=JSONObject.fromObject(inputArray.get(i));
	    				JSONObject jsonId=outputArray.getJSONObject(i);
	    				author.put("uid", jsonId.getString("rscId"));
	    				finalAuthorArray.add(author);
	    			}
	    			otherAuthorsJson=finalAuthorArray.toString();
	    			rsc.put("rscOtherAuthors", otherAuthorsJson);
	    		}
	    }
	    
	    
		return rsc;
	}
	/**
	 * Created by Jian Tang
	 * Save resource to cdo;
	 * @param input
	 * @return
	 */
	public String saveRscListToCdo(String input,Log log){
		log.debug("save resources to cdo.");
		//log.debug("Saved resources: "+input);
	    String outString="";
	    //JSONObject inJson = new JSONObject();
	    //inJson.put("methodName", "saveQueryResult");
		//inJson.put("jsonStr", input);

		try {
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+localhostUrl+":4381/LIBJson/iDlibJson?method=saveQueryResult",input, null);
			outString= (String) umo.getPayload();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	//	log.debug("Cdo returned results aftering saving resources: "+outString);
		return null;
	}
	/**
	 * function: Get the resource by resource id from CDO
	 * Input: id string
	 * output: the resource json string
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String getResourceById(String resourceId, Log log)
	{
		log.debug("Get resource by id: "+resourceId);
		JSONObject inStr = new JSONObject();   //封装接收前台传入数据使用
		inStr.put("rscId", resourceId);
		String inStrJson=inStr.toString();
		log.debug(inStrJson);
	  //  JSONObject inJson = new JSONObject();
		// inJson.put("methodName", "getResourceById");
	     //inJson.put("jsonStr", inStrJson);
		//log.debug(inputStr);		
		//log.debug("get resources from cdo.");
		String retCode="4601";
		String retMsg="Success!";
		String result="";
		JSONObject outStringJson=new JSONObject();
		outStringJson.put("retCode", retCode);
		outStringJson.put("retMsg", retMsg);
	    String outString="";
		try {
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+localhostUrl+":4381/LIBJson/iDlibJson?method=getRscInfoById",inStrJson, null);
			outString= (String) umo.getPayload();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		JSONObject json=JSONObject.fromObject(outString);
		outString=json.getString("result");
		log.debug("Get resources from cdo by id "+resourceId+":"+outString);
		outStringJson.put("result", outString);
		String output=outStringJson.toString();
		return output;
	}
	/**
	 * 
	 * @param input
	 * @param log
	 * @return
	 */
	public String getAuthorById(String input,Log log){
		return null;
	}
	
	/**
	 * function: Get the resource annotation information by resource id from AnnoSys
	 * Input: resource id string
	 * output: resource annotation json string
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String getResourceAnnoById(String resourceId, Log log)
	{
		log.debug("get resource annotation, id ="+resourceId);
		JSONObject tagJsonInput=new JSONObject();

		tagJsonInput.put("rscId", resourceId);

		String inputStr=tagJsonInput.toString();
		
		String outString = "";
		try {
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":4481/DataCenter/TagDataCenter?method=getTagListById",inputStr, null);
			outString = (String) umo.getPayload();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		log.debug("recource id= "+resourceId+" annotation information"+outString);
		return outString;
		
	}
	
	/**
	 * function: Get the resource urls by resource id  from CDOI
	 * Input: id string
	 * output: the resource urls json string
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String getResourceUrlsById(String resourceId, Log log)
	{
		JSONObject inStr = new JSONObject();   //封装接收前台传入数据使用
		
		inStr.put("rscId", resourceId);
		
		String cdoiJson = inStr.toString();
		
		log.debug(cdoiJson);
		
		String outString = "";

		  try{
			  MuleClient clientW = new MuleClient();
//			  UMOMessage umo = clientW.send("axis:http://192.168.28.112:4281/Cdoi/cdoiCdoi?method=addJson",cdoiJson,null);
			  UMOMessage umo = clientW.send("axis:http://"+remoteUrl+":4281/Cdoi/cdoiCdoi?method=getCdoiUrls",cdoiJson,null);
			  outString = (String)umo.getPayload();
		  } catch (Exception e) {
			throw new RuntimeException(e);
		  }
		return outString;
	}
	
	/**
	 * function: save the query log to ULAS
	 * Input: user id, query, user ip, query time
	 * output: return code
	 * date  :  Aug 10, 2010
	 */
	public String saveQueryLog(HttpServletRequest request, String userId, String query, String time, JSONArray rscTypeList, JSONArray fieldList, String ip, Log log)
	{
		JSONObject inJson = new JSONObject();  //封装传入后台数据使用
		JSONObject inStr = new JSONObject();   //封装接收前台传入数据使用
		
		inStr.put("userId", userId);
		inStr.put("query", query);
		inStr.put("time", time);
		String typeList="";
		for(int i=0;i<7;i++){
			if(rscTypeList.contains(String.valueOf(i+1)))
				typeList+="1";
			else
				typeList+="0";
		}
		inStr.put("rscTypeList", typeList);
		String rscFieldList="";
		for(int i=0;i<5;i++){
			if(fieldList.contains(String.valueOf(i+1)))
				rscFieldList+="1";
			else
				rscFieldList+="0";
		}
		inStr.put("fieldList", rscFieldList);
		inStr.put("ip", ip);
		
		String methodName = "saveSearchLog";
		inJson.put("methodName", methodName);
		inJson.put("jsonStr", inStr);

		String inputStr=inJson.toString();
		
		//
		log.debug("in ResourceService: inputStr="+inputStr);


		
		String outString = "0";
		
/*		*//**************获取jSon信息 start***************************//*		
		try {
			MuleClient client = new MuleClient();
			//调用WebService
			UMOMessage umo = client.send("axis:http://localhost:9281/Service/ulasService?method=rulesControl",inputStr,null);
			outString = (String)umo.getPayload();

	
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		*//**************获取jSon信息 end***************************//*
*/	
		try{
			westh.log.YyLog.rulesSave(request,inputStr);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}


		return outString; 
	}
	
	
	/**
	 * function: save the resource click log to ULAS
	 * Input: user id, query, user ip, query time
	 * output: return code
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String saveClickLog(HttpServletRequest request, String userId, String resourceId, String ip, String time, Log log)
	{
		
		JSONObject inJson = new JSONObject();  //封装传入后台数据使用
		JSONObject inStr = new JSONObject();   //封装接收前台传入数据使用
		
		
		
		inStr.put("userId", userId);
		inStr.put("time", time);
		inStr.put("rscId", resourceId);
		inStr.put("ip", ip);
		
		String methodName = "saveClickLog";
		inJson.put("methodName", methodName);
		inJson.put("jsonStr", inStr);

		String inputStr=inJson.toString();
		
		String outString = "0";
		
		//
		log.debug(inputStr);

		try{
			westh.log.YyLog.rulesSave(request,inputStr);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
		return outString; 
	}
	
	/**
	 * function: save the resource annotation information to ULAS
	 * Input: user id, resource id, resource comment, resource score, resource tags, resource read status
	 * output: return code
	 * date  :  Aug 10, 2010
	 * 
	 */
	public String saveResourceAnnoInfo(String userId, String resourceId, 
			String resourceComment, String resourceScore,String resourceTags,
			String resourceReadStatus, Log log)
	{
		JSONObject tagJsonInput=new JSONObject();

		tagJsonInput.put("userId", userId);
		tagJsonInput.put("rscId", resourceId);
		tagJsonInput.put("rscType", "");
		tagJsonInput.put("rscDes", resourceComment);
		tagJsonInput.put("score", resourceScore);
		tagJsonInput.put("tags", resourceTags);
		tagJsonInput.put("readStatus", resourceReadStatus);
		
		String inputStr=tagJsonInput.toString();
		log.debug("Annotation information:"+inputStr);
		String outString = "";
		try {
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+remoteUrl+":4481/DataCenter/TagDataCenter?method=saveTagInfo",inputStr, null);
			outString = (String) umo.getPayload();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		log.debug("Save annotation information outstring:"+outString);
		return outString; 
	}
	

	
}
